package com.oc.mba.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.oc.mba.dao.DevicePaperDAO;
import com.oc.mba.dao.OcDevicesDAO;
import com.oc.mba.dao.OcOrderDAO;
import com.oc.mba.entity.OcDevicePaper;
import com.oc.mba.entity.OcDevices;
import com.oc.mba.entity.OcOrder;

@Service
public class PaymentServiceImpl implements com.oc.mba.service.PaymentService {

	@Autowired
	private OcOrderDAO orderDAO;
	
	@Autowired
	private DevicePaperDAO devicePaperDAO;
	
	@Autowired
	private OcDevicesDAO devicesDAO;
	
	@Override
	public void save(OcOrder order) {
		orderDAO.save(order);
	}

	@Override
	public void payOrder(String orderID, String cost) {
		orderDAO.payOrder(orderID, cost);
	}

	@Override
	public OcOrder findOrder(String orderID) {
		return orderDAO.findOrder(orderID);
	}

	@Override
	public void addDevicePaper(OcDevicePaper devicePaper) {
		devicePaperDAO.save(devicePaper);
	}

	@Override
	public void addVIP(OcOrder order) {
		OcDevices device = devicesDAO.findById(order.getDeviceId());
		if (device!=null) {
			device.setLevel((short)1);
			devicesDAO.update(device);
		}
	}

	@Override
	public OcOrder findOrderByID(Integer orderID) {
		return orderDAO.findById(orderID);
	}

	@Override
	public void payOrder(OcOrder order, String cost) {
		orderDAO.payOrder(order, cost);
	}

}
